package com.firewolf.fr.s010_setting;

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

import com.firewolf.fr.s009_exception.MyHandler;

import freemarker.cache.MruCacheStorage;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class SettingDriver {
	public static void main(String[] args) throws TemplateException, IOException {

		Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
		cfg.setDirectoryForTemplateLoading(new File("ftl"));
		cfg.setTemplateExceptionHandler(new MyHandler());
		cfg.setSharedVariable("name", "zhangsan");//设置共享变量
		cfg.setNumberFormat("0.##");
		cfg.setCacheStorage(new MruCacheStorage(20, 500));//两个参数分别是一些缓存和二级缓存
		//cfg.setSetting(Configuration.CACHE_STORAGE_KEY, "strong:20,soft:250");//和上面一行等价
		cfg.clearTemplateCache();
		Template tl = cfg.getTemplate("010_setting1.ftl");
		Writer w = new OutputStreamWriter(System.out);// 把数据显示到控制台
		tl.process(null, w);
		w.flush();
	}
}
